package com.chuangtie.secondary.lining.common.response;

import com.chuangtie.secondary.lining.common.exception.OpenException;

/**
 * 统一返回结构
 *
 * @author : liaozhiwei
 * @date : 23:25 2024/7/8
 */
public class OpenResponse<T> {
    private int code;
    private String message;
    private T data;

    public OpenResponse() {
        this.code = OpenResponseCode.SUCCESS.getCode();
        this.message = OpenResponseCode.SUCCESS.getDescription();
    }

    public OpenResponse(OpenResponseCode responseCode) {
        this.code = responseCode.getCode();
        this.message = responseCode.getDescription();
    }

    public OpenResponse(T data) {
        this();
        this.data = data;
    }

    public OpenResponse(boolean complete) {
        if (complete) {
            this.code = OpenResponseCode.SUCCESS.getCode();
            this.message = OpenResponseCode.SUCCESS.getDescription();
        } else {
            throw new OpenException(OpenResponseCode.FAILED);
        }
    }

    public OpenResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

}
